package com.example.lenovo.myapplication;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class WechatAdapter extends RecyclerView.Adapter<WechatAdapter.ViewHolder> {


    private List<pep> mPepList;
    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView wechatImage;
        TextView wechatName;

        public ViewHolder(View view) {
            super(view);
            wechatImage = (ImageView) view.findViewById(R.id.wechat_image);
            wechatName = (TextView) view.findViewById(R.id.wechat_name);
        }
    }

    public WechatAdapter(List<pep> pepList) {
        mPepList = pepList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.wechat_item, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        pep peps = mPepList.get(i);
        viewHolder.wechatImage.setImageResource(peps.getImageId());
        viewHolder.wechatName.setText(peps.getName());
    }

    @Override
    public int getItemCount() {
        return mPepList.size();
    }
}
